#include <src/test/algorithm/random/boost_sobol_test.h>
void boost_sobol_test(){

	typedef particle<OS_double>					p_array_1;
	typedef particles_list<p_array_1>			p_array_2;

	std::cout << std::endl << "----start boost_sobol_test---------------------" << std::endl ;

	std::cout << std::endl << "start One dimensional test" << std::endl ;
	particle<OS_double> random1(100);
	particle<OS_double> random2(100);

	typedef boost::random::sobol_generator<32> generator1D_type;

	std::cout << std::endl << "Filling two array with 100 Sobol sampling with generator deletion after filling" << std::endl ;
	{
		generator1D_type generator1D;
		generator1D.fill(random1);
		std::cout << std::endl << "First sampling : " << random1 << std::endl ;
	}
	{
		generator1D_type generator1D;
		generator1D.fill(random2);
		std::cout << std::endl << "second sampling : " << random1 << std::endl ;
	}
	bool logical = random1==random2;
	std::cout << std::endl << "the two sampling should be equal" << (logical ? "true" : "false") << std::endl ;
	OS_DYNAMIC_CHECK(logical == true, "boost_sobol_test : logical test random1==random2 failed");

	OS_double average = jmmath::moment1(random1);
	OS_double variance = jmmath::Var(random1);

	std::cout << std::endl << "Average = " << average << " Variance " << variance;
	logical = std::abs(average-0.5) < 1./random1.size();
	OS_DYNAMIC_CHECK(logical == true, "boost_sobol_test : average test failed");
	logical = std::abs(variance- 1./12.) < 1./random1.size();
	OS_DYNAMIC_CHECK(logical == true, "boost_sobol_test : variance test failed");

	std::cout << std::endl << "start multidimensional test" << std::endl ;

	p_array_2 random_list1(1000,10);
	p_array_2 random_list2(1000,10);

	typedef std::vector<double> vector_1;
	typedef std::vector<vector_1> vector_2;

/*	vector_2 random_list1(1000);
	random_list1[0].resize(10);
	vector_2 random_list2(random_list1);
	typedef boost::random::generator_list<vector_1,generator1D_type> generatorND_type;*/

	typedef generator_list<particle<OS_double>,generator1D_type> generatorND_type;


	std::cout << std::endl << "Filling two array of 1000 Sobol sampling of dimension 10 with generator deletion after filling" << std::endl ;
	{
		generatorND_type generatorND(10);
		generatorND.fill(random_list1);
	}
	{
		generatorND_type generatorND(10);
		generatorND.fill(random_list2);
	}

	logical = random_list1==random_list2;
	std::cout << std::endl << "the two sampling should be equal" << (logical ? "true" : "false") << std::endl ;
	OS_DYNAMIC_CHECK(logical == true, "boost_sobol_test : logical test random_list1==random_list2 failed");

	particle<OS_double> averageN = jmmath::moment1(random_list2);
	OS_double varianceN = jmmath::Var(random_list2);
	std::cout << std::endl << "Average = " << averageN << " Variance " << varianceN;

	particle<OS_double> test_averageN(averageN); 
	test_averageN = 0.5;
	OS_double test_varianceN = 10./12.;

	logical = jmmath::distance(test_averageN,test_averageN) < 1./random1.size();
	OS_DYNAMIC_CHECK(logical == true, "boost_sobol_test : average ND test failed");
	logical = std::abs(varianceN - test_varianceN) < 1./random1.size();
	OS_DYNAMIC_CHECK(logical == true, "boost_sobol_test : variance ND test failed");

	std::cout << std::endl << "----End boost_sobol_test---------------------" << std::endl ;

};